#include "addinfo.h"
#include "ui_addinfo.h"
#include <QRadioButton>
#include <QPushButton>
#include <QMessageBox>
#include <QtDebug>
AddInfo::AddInfo(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::AddInfo)
{
  ui->setupUi(this);

  Person = new Individual;  //使用一个个体的结构体来缓存输入信息
  Buy = new BuyInfo;

  connect(ui->radioButtonMale, &QRadioButton::clicked, [=](){
    Person->gender = kMale;  //设置性别为男
  });

  connect(ui->radioButtonFem, &QRadioButton::clicked, [=](){
    Person->gender = KFemale;  //设置性别为女
  });

  connect(ui->ButtonCancel_2, &QPushButton::clicked, this, &QWidget::close);  //点击取消，关闭窗口
  connect(ui->pushButtonCanc, &QPushButton::clicked, this, &QWidget::close);  //点击取消，关闭窗口
  connect(ui->ButtonSave, &QPushButton::clicked, [=](){   //保存家庭信息的按钮
    Person->name = ui->EditName->text();
    Person->age = ui->spinBoxAge->value();
    Person->temperature = ui->doubleSpinBoxTemp->value();
    Person->connection = ui->lineEditCon->text();
    switch (ui->comboBox->currentIndex()) {
      case 0:
        Person->state = kHealth;
        break;
      case 1:
        Person->state = kSuspected;
        break;
      case 2:
        Person->state = kDiagnosed;
        break;
      default:
        break;
    }
    ui->EditName->clear();
    ui->lineEditCon->clear();
    ui->comboBox->setCurrentIndex(0);
    emit Save();
    this->close();
  });

  connect(ui->pushButtonSave, &QPushButton::clicked, [=](){   //保存购物信息的按钮
    Buy->goodsname = ui->EditGname->text();
    Buy->goodsnumber = ui->EditGnum->text();
    Buy->ordertime = ui->dateEdit->text();
    ui->EditGnum->clear();
    ui->EditName->clear();
    ui->dateEdit->clear();
    emit Save();
    this->close();
  });

}

void AddInfo::show_window() {
  ui->stackedWidget->setCurrentIndex(tabPage_);
  this->show();
}

AddInfo::~AddInfo()
{
  delete ui;
}
